package champPackage;

import java.util.ArrayList;
import java.util.Iterator;

public class Match {	
	private boolean held=false;
	private Team fir, sec;
	private Championship champ;
	private int firScored, secScored, matchId;
	private ArrayList<Player>scorers;
	private ArrayList<Goal>allGoals;
	
	/**
	 * creates the match with the passed teams to the passed championship
	 * @param first
	 * @param second
	 * @param ch
	 */
	public Match(Team first, Team second, Championship ch){
		fir=first;
		sec=second;
		champ=ch;
		//konsruqtors isic unda gadaeces chatarebulia tu ara
		//konstruqtors unda gaaeces matchis idic
	}
	
	/**
	 * sets number of scored goals for each team
	 * @param first_scored
	 * @param second_scored
	 */
	public void setScore(int first_scored, int second_scored){
		firScored=first_scored;
		secScored=second_scored;
	}
	/**
	 * return the championship object where the match was held
	 * @return
	 */
	public Championship getChampionhip(){
		
		return champ;		
	}
	/**
	 * tells whtere the match is already complete
	 * @return
	 */
	public boolean isHeld(){
		
		return held;
	}
	/**
	 * returns the first (not a winner) team of the match
	 */
	public Team getFirstTeam(){
		return fir;
	}
	/**
	 * returns the second (not a winner) team of the match
	 * @return
	 */
	public Team getSecondTeam(){
		return sec;
	}
	/**
	 * number of goals first team scored
	 * @return returns null if match is not held
	 */
	public Integer firstTeamScored(){
		if(isHeld())
		return firScored;
		
		return null;
	}
	/**
	 * number of goals second team scored
	 * @return
	 */
	public Integer secondTeamScored(){
		if(isHeld())
			return secScored;
			
			return null;
	}
	
	/**
	 * return id from the dataBase (calls databaseManager)
	 * @return
	 */
	public int getMatchId(){
		return matchId;
	}
	/**
	 * return players from the both team who scored goals
	 * @return
	 */
	public Iterator<Player>getScorers(){
	
		return scorers.iterator();
	}
	/**
	 * this method returns either -1 (if the first team loosed)
	 * or 0 (in case of draw)
	 * or 1 (if first team is winner)
	 * @return
	 */
	public int matchResult(){
		if(firstTeamScored()>secondTeamScored())return 1;
		if(firstTeamScored()<secondTeamScored())return -1;
		return 0;
	}
	
	/**
	 * returns all the goals scored in this match
	 * @return
	 */
	public Iterator<Goal> getGoals(){
		return allGoals.iterator();
	}
	
	/**
	 * sets scorers from rach team, which is received from dataBase
	 * @param firstTeamScorers
	 */
	public  void setScorers (ArrayList<Player>goalScorers) {
		scorers=goalScorers;
	}
	
	/**
	 * gives information about all goals to the class object
	 * @param list
	 */
	public void setGoals(ArrayList<Goal>list){
		allGoals=list;
	}
	

	
}
